
require('@/libs/rqconnect/xterm.js')
require('@/libs/rqconnect/xterm.css')

import { Terminal } from 'xterm'
import * as fit from 'xterm/lib/addons/fit/fit'
import * as attach from 'xterm/lib/addons/attach/attach'
Terminal.applyAddon(fit)
Terminal.applyAddon(attach)

let str = window.location.search
console.log(str.indexOf('wsurl='))
var wsurl = str.substring(str.indexOf('wsurl=') + ("wsurl=").length)
console.log(wsurl)



let terminalContainer = document.getElementById('terminal')
var term = new Terminal({
    cols: 145,
    rows: 39,
    cursorBlink: 5,
    scrollback: 100,
    tabStopWidth: 4,
})
term.open(terminalContainer)
// open websocket 

var  runRealTerminal  = function () {
  console.log('webSocket is finished')
}
var errorRealTerminal = function () {
  console.log('error')
}
var closeRealTerminal = function () {
  console.log('close')
}

var terminalSocket = new WebSocket(wsurl)
terminalSocket.onopen = runRealTerminal
terminalSocket.onclose = closeRealTerminal
terminalSocket.onerror = errorRealTerminal
term.attach(terminalSocket)
term._initialized = true
console.log('mounted is going on')


